using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
namespace DAO
{
    public class DocGia : Interface
    {
        string s = Application.StartupPath;
        public DataTable Load()
        {
            Provider prv = new Provider("Server=.\\SQLEXPRESS;AttachDbFilename=" + s + "\\QLTV.mdf; Trusted_Connection=Yes;Integrated security=true;User Instance=true");
            DataTable dt = prv.ExecuteStoreProcedure("sp_SelectDocGia");
            if(dt==null)
            {
                Provider prv1 = new Provider("Server=.\\;AttachDbFilename=" + s + "\\QLTV.mdf; Trusted_Connection=Yes;Integrated security=true;User Instance=true");
                dt = prv1.ExecuteStoreProcedure("sp_SelectDocGia");
            }
            return dt;
        }

        public bool InsertByStoreProcedure(string nameSP , string[] paraName , object[] paraValue)
        {
            try
            {
                Provider prv = new Provider("Server=.\\SQLEXPRESS;AttachDbFilename=" + s + "\\QLTV.mdf; Trusted_Connection=Yes;Integrated security=true;User Instance=true");
                prv.ExecuteStoreProcedure(nameSP , paraName , paraValue);
                return true;
            }
            catch
            {
                try
                {
                    Provider prv1 = new Provider("Server=.\\;AttachDbFilename=" + s + "\\QLTV.mdf; Trusted_Connection=Yes;Integrated security=true;User Instance=true");
                    prv1.ExecuteStoreProcedure(nameSP , paraName , paraValue);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }

        public static bool PhatSinhMaDocGia(DTO.DocGia nv)
        {
            string sql = "select MaDocGia from DocGia";
            DataTable dt = Interface.SelectTest(sql);
            if (dt != null)
            {
                DataRow dr = dt.Rows[dt.Rows.Count - 1];
                int ma = int.Parse(dr["MaDocGia"].ToString());
                ma++;
                nv.MaDocGia = ma.ToString();
                return true;
            }
            else
                return false;
        }


    }
}
